package network;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class User {

	

	private InetAddress ip;
	private String name;
	
	public User(){
		this(null);
	}
	public User(InetAddress i){
		this(i,i.getHostAddress());
	}
	public User(String str, String inet){
		name = str;
		try {
			ip = InetAddress.getByName(inet);
		} catch (UnknownHostException e) {
			ip = null;
		}
	}
	public User(InetAddress i, String str){
		ip = i;
		name = str;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public InetAddress getIp() {
		return ip;
	}
	
	public String toString(){
		return "User\n\tIP: "+ip.toString()+"\nNAME: "+name;
	}

	public String get(){
		return name+"/"+ip.getHostAddress();
	}
	
	public boolean equals(Object o){
		if(o instanceof User){
			User u = (User)o;
			return (u.getIp().equals(this.getIp()) && u.getName().equals(this.name));
		}
		return false;
	}
}
